# -*- coding: utf-8 -*-
# coding:utf-8

from django import template
register = template.Library()

__author__ = 'lancelrq'


def cproblem_index(value, arg=None):
    try:
        if arg is None:
            return gen_idx(value)
        else:
            if isinstance(arg, dict):
                idx = arg.get(value)
                return gen_idx(idx)
            else:
                return "NaN"
    except:
        return "NaN"


def gen_idx(value):
    v = int(value)
    outstr = ""
    while v > 0:
        outstr = chr(v % 26 + 64) + outstr
        v /= 26
    return outstr

register.filter('cproblem_index', cproblem_index)